<?php

namespace app\admin\model\usermanage;

use think\Model;
use traits\model\SoftDelete;

class UsersWage extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'users_wage';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'audit_time_text'
    ];
    

    



    public function getAuditTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['audit_time']) ? $data['audit_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setAuditTimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }



    public function users()
    {
        return $this->belongsTo('Users', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'store_id' => 'Store ID',
            'user_id' => '用户ID',
            'type' => '工资类型,1是推荐人店补,2是团队业绩满足42120,3是团队业绩满足126000,4是团队业绩满足179100,5是下级激活奖励',
            'money' => '金额',
            'integral' => '积分',
            'status' => '0待审核,1已审核发放',
            'audit_time' => '审核时间',
            'is_delete' => 'Is Delete',
            'addtime' => 'Addtime',
            'order_id'=>'订单id',
            'group_pv_id'=>'分组比较的id',
            'money_type'=>'2是团队业绩满足42120,3是团队业绩满足126000,4是团队业绩满足179100'
        ];
    }

    public static function set($money, $user_id, $type = 1,$order_id=0,$integral=0,$group_pv_id=0)
    {
        $model = new UsersWage();
        $model->user_id = $user_id;
        $model->setAttr('type',$type);
        $model->money = $money;
        $model->integral = $integral;
        $model->order_id = $order_id;
        $model->group_pv_id = $group_pv_id;
        return $model->save();
    }
}
